package com.yonyou.brigade.third_parties.huazhu.service.impl;

import com.yonyou.brigade.third_parties.huazhu.service.IHzPublicService;
import com.yonyou.brigade.util.operateutil.AESUtil4ECB;
import com.yonyou.brigade.util.operateutil.SHA256Utils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class HzPublicServiceImpl implements IHzPublicService {

    @Value("${huazhu.password}")
    private String password;

    @Override
    public String getToken() {
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = sf.format(new Date());
        return AESUtil4ECB.encryptUtf8(date, password);
    }

    @Override
    public String getToken(String configPassword) {
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = sf.format(new Date());
        return AESUtil4ECB.encryptUtf8(date, configPassword);
    }

    @Override
    public String getSecretString(String time, String srcId, String vCard) {
       return getSecretString(time, srcId, vCard, password);
    }

    @Override
    public String getSecretString(String time, String srcId, String vCard, String configPassword) {
        StringBuilder builder = new StringBuilder();
        builder.append(configPassword);
        builder.append("SrcID=");
        builder.append(srcId);
        builder.append("&VCard=");
        builder.append(vCard);
        builder.append("&Time=");
        builder.append(time);
        builder.append(configPassword);
        return SHA256Utils.getSHA256(builder.toString());
    }
}
